package student;

import java.util.Arrays;

//按年龄
public class demo {
    public static void bubbleSort(Student[] students) {
        for (int i = 0; i < students.length-1; i++) {
            for (int j = 0; j < students.length-1-i; j++) {
                if(students[j].compareTo(students[j+1]) > 0) {
                    Student tmp = students[j];
                    students[j] = students[j+1];
                    students[j+1] = tmp;
                }
            }
        }
    }
    public static void main(String[] args) {
        Student[] students = {new Student("张三",10),
                new Student("李四",4),
                new Student("王五",5)};
        System.out.println("按年龄排序:");
        System.out.println("排序前： "+Arrays.toString(students));

        bubbleSort(students);

        System.out.println("排序后： "+Arrays.toString(students));
    }
}